#include <iostream>
#include <string>
#include <memory>
//工厂方法  区别于简单工厂，单独设置一个抽象和一系列的实现类，实现不同的生产工厂
class AbstracCalc
{
public:
    using ptr = std::shared_ptr<AbstracCalc>;
    virtual int getResult(int num1, int num2)
    {
        return 0;
    }
};

class Add : public AbstracCalc
{
public:
    int getResult(int num1, int num2) override
    {
        return num1 + num2;
    }
};

class Minus : public AbstracCalc
{
public:
    int getResult(int num1, int num2) override
    {
        return num1 - num2;
    }
};

class Multi : public AbstracCalc
{
public:
    int getResult(int num1, int num2) override
    {
        return num1 * num2;
    }
};

class Divide : public AbstracCalc
{
public:
    int getResult(int num1, int num2) override
    {
        return num1 / num2;
    }
};
//工厂方法模式
class AbstractFac
{
public:
    using ptr = std::shared_ptr<AbstractFac>;
    virtual AbstracCalc::ptr getOper() = 0;
protected:
    AbstracCalc::ptr calc;
};
class AddFactory : public AbstractFac
{
public:
    virtual AbstracCalc::ptr getOper() override
    {
        return std::make_shared<Add>();
    }
};

class MinusFactory : public AbstractFac
{
public:
    virtual AbstracCalc::ptr getOper() override
    {
        return std::make_shared<Minus>();
    }
};

class MultiFactory : public AbstractFac
{
public:
    virtual AbstracCalc::ptr getOper() override
    {
        return std::make_shared<Multi>();
    }
};

class DivideFactory : public AbstractFac
{
public:
    virtual AbstracCalc::ptr getOper() override
    {
        return std::make_shared<Divide>();
    }
};

int main(int argc, char **argv)
{
    int a = 10;
    int b = 20;
    std::cout << "hello world" << std::endl;
    AbstractFac::ptr factory(new MultiFactory);
    AbstracCalc::ptr calc=factory->getOper();
    std::cout << "a*b=" << calc->getResult(a, b) << std::endl;
    factory=std::make_shared<AddFactory>();
    calc=factory->getOper();
    std::cout << "a+b=" << calc->getResult(a, b) << std::endl;
    std::cout << "hello world" << std::endl;
    return 0;
}